<?php
/**
 * @link http://cn2.php.net/manual/en/migration54.incompatible.php
 * @version $Id: 13_htmlentities_chinese_ansi.php 214 2012-03-02 12:17:58Z horseluke@126.com $
 */

/*
13. If you use htmlentities() with asian character sets, 
it works like htmlspecialchars() - this has always been 
the case in previous versions of PHP, but now an E_STRICT 
level error is emitted.

NOTE:
php开发组在某个bug指出，由于安全的原因，在PHP5.4及以后如果要使用
htmlspecialchars和htmlentities时，若内容并非UTF-8编码且未指定
第三个参数$charset，将全部丢弃：
https://bugs.php.net/bug.php?id=55174
https://bugs.php.net/bug.php?id=60714
http://cn.php.net/htmlspecialchars

PHP 5.3:
PLEASE REFER:
https://bugs.php.net/bug.php?id=55174
https://bugs.php.net/bug.php?id=60714
http://cn.php.net/htmlspecialchars
====================================

b-htmlspecialchars without encoding:(strlen:59)求双屏，速度～     &lt;script&gt;
alert('1');&lt;/script&gt;

c-htmlentities without encoding:(strlen:143)&Ccedil;&oacute;&Euml;&laquo;&AElig;
&Aacute;&pound;&not;&Euml;&Ugrave;&para;&Egrave;&iexcl;&laquo;     &lt;script&gt
;alert('1');&lt;/script&gt;

================================================
b-htmlspecialchars with encoding:(strlen:59)求双屏，速度～     &lt;script&gt;ale
rt('1');&lt;/script&gt;

c-htmlentities with encoding:(strlen:59)求双屏，速度～     &lt;script&gt;alert('
1');&lt;/script&gt;

================================================
b-htmlspecialchars with ini_set default_charset:(strlen:59)求双屏，速度～     &l
t;script&gt;alert('1');&lt;/script&gt;

c-htmlentities with ini_set default_charset:(strlen:143)&Ccedil;&oacute;&Euml;&l
aquo;&AElig;&Aacute;&pound;&not;&Euml;&Ugrave;&para;&Egrave;&iexcl;&laquo;     &
lt;script&gt;alert('1');&lt;/script&gt;



PHP 5.4:
PLEASE REFER:
https://bugs.php.net/bug.php?id=55174
https://bugs.php.net/bug.php?id=60714
http://cn.php.net/htmlspecialchars
====================================

b-htmlspecialchars without encoding:(strlen:0)

c-htmlentities without encoding:(strlen:0)

================================================

Strict Standards: htmlentities(): Only basic entities substitution is supported
for multi-byte encodings other than UTF-8; functionality is equivalent to htmlsp
ecialchars in D:\htdoc_custom\php_5_4\13_htmlentities_chinese_ansi.php on line 1
09
b-htmlspecialchars with encoding:(strlen:59)求双屏，速度～     &lt;script&gt;ale
rt('1');&lt;/script&gt;

c-htmlentities with encoding:(strlen:59)求双屏，速度～     &lt;script&gt;alert('
1');&lt;/script&gt;

================================================
b-htmlspecialchars with ini_set default_charset:(strlen:0)

c-htmlentities with ini_set default_charset:(strlen:0)
*/
error_reporting(E_ALL | E_STRICT);

echo "PLEASE REFER:
https://bugs.php.net/bug.php?id=55174
https://bugs.php.net/bug.php?id=60714
http://cn.php.net/htmlspecialchars
====================================

";


$a = "求双屏，速度～     <script>alert('1');</script>";
//$a = "<script>alert('1');</script>";
$a = mb_convert_encoding($a, 'GB2312', 'UTF-8');

$b = htmlspecialchars($a);
$c = htmlentities($a);
echo 'b-htmlspecialchars without encoding:(strlen:'. strlen($b).')'. $b. "\r\n\r\n";
echo 'c-htmlentities without encoding:(strlen:'. strlen($c).')'. $c. "\r\n\r\n";

echo "================================================\r\n";
$b = htmlspecialchars($a, ENT_COMPAT, 'GB2312');
$c = htmlentities($a, ENT_COMPAT, 'GB2312');
echo 'b-htmlspecialchars with encoding:(strlen:'. strlen($b).')'. $b. "\r\n\r\n";
echo 'c-htmlentities with encoding:(strlen:'. strlen($c).')'. $c. "\r\n\r\n";

echo "================================================\r\n";
//虽然是PHP_INI_ALL，但似乎无效
ini_set('default_charset', 'ISO-8859-1');
$b = htmlspecialchars($a);
$c = htmlentities($a);
echo 'b-htmlspecialchars with ini_set default_charset:(strlen:'. strlen($b).')'. $b. "\r\n\r\n";
echo 'c-htmlentities with ini_set default_charset:(strlen:'. strlen($c).')'. $c. "\r\n\r\n";
